home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / files.c < prev    next >
C/C++ Source or Header  |  1994-09-16  |  13KB  |  378 lines

  1. /* System-dependent definitions of various files, spool directories, etc */
  2. /*
  3.  *      25/06/92    paul@wolf.demon.co.uk added '@' and '~' password
  4.  *                  flags
  5.  *
  6.  * ATARI ST NOS version by David Nash - dnash@chaos.demon.co.uk
  7.  *
  8.  * 10.03.93 - Add Newsqueue path for nntpcli post/profile commands
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include "global.h"
  13. #include "netuser.h"
  14. #include "files.h"
  15.  
  16. #ifdef    MSDOS
  17. char *Startup = "/autoexec.net";    /* Initialization file */
  18. char *Userfile = "/ftpusers";    /* Authorized FTP users and passwords */
  19. char *Mailkill = "/mailkill"; /* SMTP sender reject file */
  20. char *Maillog = "/spool/mail.log";    /* mail log */
  21. char *Mailspool = "/spool/mail";    /* Incoming mail */
  22. char *Mailqdir = "/spool/mqueue";        /* Outgoing mail spool */
  23. char *Mailqueue = "/spool/mqueue/*.wrk";    /* Outgoing mail work files */
  24. char *Routeqdir = "/spool/rqueue";        /* queue for router */
  25. char *Alias = "/alias";        /* the alias file */
  26. char *Dfile = "/domain.txt";    /* Domain cache */
  27. char *Dzones = "/spool/zones";    /* Zone file directory */
  28. char *Dscripts = "/spool/scripts";    /* Script file directory */
  29. char *Dboot = "/named.boo";    /* Nameserver boot file */
  30. char *Fdir = "/finger";        /* Finger info directory */
  31. char *Arealist = "/spool/areas";/* List of message areas */
  32. char *Helpdir = "/spool/help";    /* Mailbox help file directory */
  33. char *Rewritefile = "/spool/rewrite"; /* Address rewrite file */
  34. char *Newsdir = "/spool/news";        /* News messages and NNTP data */
  35. char *Popusers = "/popusers";        /* POP user and passwd file */
  36. char *Signature = "/spool/signatur"; /* Mail signature file directory */
  37. char *Forwardfile = "/spool/forward.bbs"; /* Mail forwarding file */
  38. char *Historyfile = "/spool/history"; /* Message ID history file */
  39. char *Scripts = "/scripts";    /* PPP up/down scripts */
  40. char Eol[] = "\r\n";
  41. #define    SEPARATOR    "/"
  42. #endif
  43.  
  44. #ifdef    ATARI
  45. char *Startup = "/startup.nos";                /* Initialization file                 */
  46. char *Userfile = "/ftpusers";                    /* Authorized FTP users             */
  47. char *Mailkill = "/mailkill";                    /* SMTP sender reject file            */
  48. char *Maillog = "/spool/mail.log";            /* mail log                             */
  49. char *Mailspool = "/spool/mail";                /* Incoming mail                         */
  50. char *Mailqdir = "/spool/mqueue";            /* Outgoing mail spool                 */
  51. char *Mailqueue = "/spool/mqueue/*.wrk";    /* Outgoing mail work files         */
  52. char *Routeqdir = "/spool/rqueue";            /* queue for router                     */
  53. char *Alias = "/alias";                            /* the alias file                     */
  54. char *Dfile = "/domain.txt";                    /* Domain cache                         */
  55. char *Dzones = "/spool/zones";                /* Zone file directory                 */
  56. char *Dscripts = "/spool/scripts";            /* Script file directory             */
  57. char *Dboot = "/named.rc";                        /* Nameserver boot file             */
  58. char *Fdir = "/finger";                            /* Finger info directory             */
  59. char *Arealist = "/spool/areas";                /* List of message areas             */
  60. char *Helpdir = "/spool/help";                /* Mailbox help file directory     */
  61. char *Rewritefile = "/spool/rewrite";         /* Address rewrite file             */
  62. char *Newsdir = "/spool/news";                /* News messages and NNTP data     */
  63. char *Newsqdir = "/spool/mqueue";            /* Outgoing news files                 */
  64. char *Newsqueue = "/spool/mqueue/*.nwk";    /* Outgoing news work files         */
  65. char *Popusers = "/popusers";                    /* POP user and passwd file         */
  66. char *Signature = "/spool/sig";                 /* Mail signature file directory */
  67. char *Forwardfile = "/spool/forward.bbs"; /* Mail forwarding file             */
  68. char *Historyfile = "/spool/history";         /* Message ID history file         */
  69. char *Scripts = "/scripts";                    /* PPP up/down scripts                 */
  70. char Eol[] = "\n";
  71. #define    SEPARATOR    "/"
  72. #endif
  73.  
  74. #ifdef    UNIX
  75. char *Startup = "./startup.net";    /* Initialization file */
  76. char *Config = "./config.net";    /* Device configuration list */
  77. char *Userfile = "./ftpusers";
  78. char *Mailspool = "./mail";
  79. char *Maillog = "./mail.log";    /* mail log */
  80. char *Mailqdir = "./mqueue";
  81. char *Mailqueue = "./mqueue/*.wrk";
  82. char *Routeqdir = "./rqueue";        /* queue for router */
  83. char *Alias = "./alias";    /* the alias file */
  84. char *Dfile = "./domain.txt";    /* Domain cache */
  85. char *Fdir = "./finger";        /* Finger info directory */
  86. char *Arealist = "./areas";        /* List of message areas */
  87. char *Helpdir = "./help";    /* Mailbox help file directory */
  88. char *Rewritefile = "./rewrite"; /* Address rewrite file */
  89. char *Newsdir = "./news";        /* News messages and NNTP data */
  90. char *Popusers = "./popusers";        /* POP user and passwd file */
  91. char *Signature = "./signatur"; /* Mail signature file directory */
  92. char *Forwardfile = "./forward.bbs"; /* Mail forwarding file */
  93. char *Historyfile = "./history"; /* Message ID history file */
  94. #define    SEPARATOR    "/"
  95. char Eol[] = "\n";
  96. #endif
  97.  
  98. #ifdef    AMIGA
  99. char *Startup = "TCPIP:net-startup";
  100. char *Config = "TCPIP:config.net";    /* Device configuration list */
  101. char *Userfile = "TCPIP:ftpusers";
  102. char *Mailspool = "TCPIP:spool/mail";
  103. char *Maillog = "TCPIP:spool/mail.log";
  104. char *Mailqdir = "TCPIP:spool/mqueue";
  105. char *Mailqueue = "TCPIP:spool/mqueue/#?.wrk";
  106. char *Routeqdir = "TCPIP:spool/rqueue";        /* queue for router */
  107. char *Alias = "TCPIP:alias";    /* the alias file */
  108. char *Dfile = "TCPIP:domain.txt";    /* Domain cache */
  109. char *Fdir = "TCPIP:finger";        /* Finger info directory */
  110. char *Arealist = "TCPIP:spool/areas";    /* List of message areas */
  111. char *Helpdir = "TCPIP:spool/help";    /* Mailbox help file directory */
  112. char *Rewritefile = "TCPIP:spool/rewrite"; /* Address rewrite file */
  113. char *Newsdir = "TCPIP:spool/news";    /* News messages and NNTP data */
  114. char *Popusers = "TCPIP:/popusers";    /* POP user and passwd file */
  115. char *Signature = "TCPIP:spool/signatur"; /* Mail signature file directory */
  116. char *Forwardfile = "TCPIP:spool/forward.bbs"; /* Mail forwarding file */
  117. char *Historyfile = "TCPIP:spool/history"; /* Message ID history file */
  118. #define    SEPARATOR    "/"
  119. char Eol[] = "\r\n";
  120. #endif
  121.  
  122. #ifdef    MAC
  123. char *Startup ="Mikes Hard Disk:net.start";
  124. char *Config = "Mikes Hard Disk:config.net";    /* Device configuration list */
  125. char *Userfile = "Mikes Hard Disk:ftpusers";
  126. char *Mailspool = "Mikes Hard Disk:spool:mail:";
  127. char *Maillog = "Mikes Hard Disk:spool:mail.log:";
  128. char *Mailqdir = "Mikes Hard Disk:spool:mqueue:";
  129. char *Mailqueue = "Mikes Hard Disk:spool:mqueue:*.wrk";
  130. char *Routeqdir = "Mikes Hard Disk:spool/rqueue:";    /* queue for router */
  131. char *Alias = "Mikes Hard Disk:alias";    /* the alias file */
  132. char *Dfile = "Mikes Hard Disk:domain:txt";    /* Domain cache */
  133. char *Fdir = "Mikes Hard Disk:finger";        /* Finger info directory */
  134. char *Arealist = "Mikes Hard Disk:spool/areas";    /* List of message areas */
  135. char *Helpdir = "Mikes Hard Disk:spool/help"; /* Mailbox help file directory */
  136. char *Rewritefile = "Mikes Hard Disk:spool/rewrite"; /* Address rewrite file */
  137. char *Newsdir = "Mikes Hard Disk:spool/news"; /* News messages and NNTP data */
  138. char *Popusers = "Mikes Hard Disk:/popusers";    /* POP user and passwd file */
  139. char *Signature = "Mikes Hard Disk:spool/signatur"; /* Mail signature file directory */
  140. char *Forwardfile = "Mikes Hard Disk:spool/forward.bbs"; /* Mail forwarding file */
  141. char *Historyfile = "Mikes Hard Disk:spool/history"; /* Message ID history file */
  142. #define    SEPARATOR    ":"
  143. char Eol[] = "\r";
  144. #endif
  145.  
  146. static char *rootdir = "";
  147.  
  148. /* Establish a root directory other than the default. Can only be called
  149.  * once, at startup time
  150.  */
  151. void
  152. initroot(root)
  153. char *root;
  154. {
  155.     rootdir = strdup( root );
  156.  
  157.     Startup = rootdircat(Startup);
  158.     Userfile = rootdircat(Userfile);
  159.     Mailkill = rootdircat(Mailkill);
  160.     Maillog = rootdircat(Maillog);
  161.     Mailspool = rootdircat(Mailspool);
  162.     Mailqdir = rootdircat(Mailqdir);
  163.     Mailqueue = rootdircat(Mailqueue);
  164.     Routeqdir = rootdircat(Routeqdir);
  165.     Alias = rootdircat(Alias);
  166.     Dfile = rootdircat(Dfile);
  167.     Dzones = rootdircat(Dzones);
  168.     Dscripts = rootdircat(Dscripts);
  169.     Dboot = rootdircat(Dboot);
  170.     Fdir = rootdircat(Fdir);
  171.     Arealist = rootdircat(Arealist);
  172.     Helpdir = rootdircat(Helpdir);
  173.     Rewritefile = rootdircat(Rewritefile);
  174.     Newsdir = rootdircat(Newsdir);
  175.     Newsqdir = rootdircat(Newsqdir);
  176.     Newsqueue = rootdircat(Newsqueue);
  177.     Signature = rootdircat(Signature);
  178.     Forwardfile = rootdircat(Forwardfile);
  179.     Historyfile = rootdircat(Historyfile);
  180.     Scripts = rootdircat(Scripts);
  181. }
  182.  
  183. /* Concatenate root, separator and arg strings into a malloc'ed output
  184.  * buffer, then remove repeated occurrences of the separator char
  185.  */
  186. char *
  187. rootdircat(filename)
  188. char *filename;
  189. {
  190.     char *out = filename;
  191.  
  192.     if ( strlen(rootdir) > 0 ) {
  193.         char *separator = SEPARATOR;
  194.  
  195.         out = mallocw( strlen(rootdir)
  196.                 + strlen(separator)
  197.                 + strlen(filename) + 1);
  198.  
  199.         strcpy(out,rootdir);
  200.         strcat(out,separator);
  201.         strcat(out,filename);
  202.         if(*separator != '\0'){
  203.             char *p1, *p2;
  204.  
  205.             /* Remove any repeated occurrences */
  206.             p1 = p2 = out;
  207.             while(*p2 != '\0'){
  208.                 *p1++ = *p2++;
  209.                 while(p2[0] == p2[-1] && p2[0] == *separator)
  210.                     p2++;
  211.             }
  212.             *p1 = '\0';
  213.         }
  214.     }
  215.     return out;
  216. }
  217.  
  218. /* Read through FTPUSERS looking for user record
  219.  * Returns line which matches username, or NULLCHAR when no match.
  220.  * Each of the other variables must be copied before freeing the line.
  221.  */
  222. char *
  223. userlookup(username,password,directory,permission,ip_address)
  224. char *username;
  225. char **password;
  226. char **directory;
  227. int   *permission;
  228. int32 *ip_address;
  229. {
  230.     FILE *fp;
  231.     char *buf;
  232.     char *cp;
  233.  
  234.     if((fp = fopen(Userfile,READ_TEXT)) == NULLFILE)
  235.         /* Userfile doesn't exist */
  236.         return NULLCHAR;
  237.  
  238.     buf = mallocw(128);
  239.     while ( fgets(buf,128,fp) != NULLCHAR ){
  240.         if(*buf == '#')
  241.             continue;    /* Comment */
  242.  
  243.         if((cp = strchr(buf,' ')) == NULLCHAR)
  244.             /* Bogus entry */
  245.             continue;
  246.         *cp++ = '\0';        /* Now points to password */
  247.  
  248.         if( stricmp(username,buf) == 0 )
  249.             break;        /* Found user */
  250.     }
  251.     if(feof(fp)){
  252.         /* username not found in file */
  253.         fclose(fp);
  254.         free(buf);
  255.         return NULLCHAR;
  256.     }
  257.     fclose(fp);
  258.  
  259.     if ( password != NULL )
  260.         *password = cp;
  261.  
  262.     /* Look for space after password field in file */
  263.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  264.         /* Invalid file entry */
  265.         free(buf);
  266.         return NULLCHAR;
  267.     }
  268.     *cp++ = '\0';    /* Now points to directory field */
  269.  
  270.     if ( directory != NULL )
  271.         *directory = cp;
  272.  
  273.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  274.         /* Permission field missing */
  275.         free(buf);
  276.         return NULLCHAR;
  277.     }
  278.     *cp++ = '\0';    /* now points to permission field */
  279.  
  280.     if ( permission != NULL )
  281.         *permission = (int)strtol( cp, NULLCHARP, 0 );
  282.  
  283.     if((cp = strchr(cp,' ')) == NULLCHAR) {
  284.         /* IP address missing */
  285.         if ( ip_address != NULL )
  286.             *ip_address = 0L;
  287.     } else {
  288.         *cp++ = '\0';    /* now points at IP address field */
  289.         if ( ip_address != NULL )
  290.             *ip_address = resolve( cp );
  291.     }
  292.     return buf;
  293. }
  294.  
  295. /* Subroutine for logging in the user whose name is name and password is pass.
  296.  * The buffer path should be long enough to keep a line from the userfile.
  297.  * If pwdignore is true, the password check will be overridden.
  298.  * The return value is the permissions field or -1 if the login failed.
  299.  * Path is set to point at the path field, and pwdignore will be true if no
  300.  * particular password was needed for this user.
  301.  */
  302. int
  303. userlogin(name,pass,path,len,pwdignore)
  304. char *name;
  305. char *pass;
  306. char **path;
  307. int len;            /* Length of buffer pointed at by *path */
  308. int *pwdignore;
  309. {
  310.     char *buf;
  311.     char *password;
  312.     char *directory;
  313.     int permission;
  314.     int anonymous;
  315.     char *cp;
  316.     int failed=0;
  317.  
  318.     if ( (buf = userlookup( name, &password, &directory,
  319.             &permission, NULL )) == NULLCHAR ) {
  320.         return -1;
  321.     }
  322.  
  323.     anonymous = *pwdignore;
  324.     if ( strcmp(password,"*") == 0 )
  325.         anonymous = TRUE;    /* User ID is password-free */
  326.  
  327.     if ( strcmp(password,"~") == 0 )
  328.         failed=1;           /* 'Dummy' user - (needed for SMTP bouncing) */
  329.  
  330.     if ( strcmp(password,"@") == 0 )
  331.     {
  332.         anonymous = TRUE;   /* Only check for '@' in the password */
  333.         if (strchr(pass,'@') == NULLCHAR)
  334.             failed=1;
  335.     }
  336.  
  337.     if((!anonymous && strcmp(password,pass) != 0)||(failed)) {
  338.         /* Password required, but wrong one given */
  339.         free(buf);
  340.         return -1;
  341.     }
  342.  
  343.     if ( strlen( directory ) + 1 > len ) {
  344.         /* not enough room for path */
  345.         free(buf);
  346.         return -1;
  347.     }
  348.  
  349. #if   defined(AMIGA)
  350.     /*
  351.      * Well, on the Amiga, a file can be referenced by many names:
  352.      * device names (DF0:) or volume names (My_Disk:).  This hunk of code
  353.      * passed the pathname specified in the ftpusers file, and gets the
  354.      * absolute path copied into the user's buffer.  We really should just
  355.      * allocate the buffer and return a pointer to it, since the caller
  356.      * really doesn't have a good idea how long the path string is..
  357.      */
  358.     if ( (directory = pathname("", directory)) != NULLCHAR ) {
  359.         strcpy(*path, directory);
  360.         free(directory);
  361.     } else {
  362.         **path = '\0';
  363.     }
  364. #else
  365.     strcpy(*path,directory);
  366.     /* Convert any backslashes to forward slashes, for backward
  367.      * compatibility with the old NET
  368.      */
  369.     while((cp = strchr(*path,'\\')) != NULLCHAR)
  370.         *cp = '/';
  371. #endif
  372.     free(buf);
  373.     *pwdignore = anonymous;
  374.     /* Finally return the permission bits */
  375.     return permission;
  376. }
  377.  
  378.